package com.ofd.sign.utils;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.UUID;

import static com.ofd.sign.constant.CoreConstants.OFD_FILE_POSTFIX;

/**
 * @author wangrenjie
 */
@Slf4j
public class CoreUtil {

    private static final InheritableThreadLocal<String> CURRENT_SYS_ID = new InheritableThreadLocal<>();


    public static String getSysId() {
        return CURRENT_SYS_ID.get();
    }


    public static void setSysId(String sysId) {
        if (StrUtil.isNotBlank(sysId)) {
            CURRENT_SYS_ID.set(sysId);
        }
    }

    public static void cleanSysId() {
        try {
            CURRENT_SYS_ID.remove();
        }catch (Exception ig){
          //忽略
        }
    }


    /**
     * 获取缓存文件路径
     *
     * @return
     */
    public static String getTempFilePath() {
        return getTempFilePath(OFD_FILE_POSTFIX);
    }

    /**
     * 获取缓存文件路径
     *
     * @return
     */
    public static String getTempFilePath(String postfix) {
        return FileUtil.getTmpDirPath() + FileUtil.FILE_SEPARATOR + UUID.randomUUID() + postfix;
    }

}
